<?php

namespace lib\Server;


use lib\Root;
use lib\Server\Service\HttpService;

class HttpServer
{
	static public function start($config, $public_options = [])
	{
		if (Server::$swoole_instance) {
			(new TcpHttpsServer())->start($config, $public_options);
		}
		else {
			Root::stdout("{$config['id']} HttpServer ready");

			$http = new \swoole_http_server($config['host'], $config['port']);
			$http->on('request', [
				new HttpService($config['container'] ?: null),
				'handler'
			]);
			if ($config['options']) $http->set($config['options']);

			Server::$swoole_instance = &$http;
		}
	}
}